<?php


namespace app\controller\admin;


use app\common\model\HomeStatisticsModel;
use think\Response;

class Home extends Base
{

    /**
     * @func userCount
     * @param type 0--用户构成 1--宿舍楼
     * @param school_id 学校id
     * @method GET
     * @desc 获取指定学校的用户构成和宿舍楼用户数量统计
     * @return Response
     * @Time: 2021/12/24 16:37
     */
    public function userAmount(): Response
    {
        $type = $this->request->get('type', 0);
        $school_id = $this->request->get('school_id', $this->userInfo['school_id']);

        if ($type == 1) {
            $list = HomeStatisticsModel::dorUserCount($school_id);
        } else {
            $list = HomeStatisticsModel::sexStructureAmount($school_id);
        }
        return $this->buildSuccess([
            'list' => $list
        ]);
    }

    /**
     * @func userActive
     * @param school_id 学校id dormitory_id 宿舍楼id date_type 日期类型 1--今天 2--昨天 3--近7天
     * @method GET
     * @desc 用户活跃数据
     * @return Response
     * @Time: 2022/1/11 18:05
     */
    public function userActive(): Response
    {
        $school_id = $this->request->get('school_id', $this->userInfo['school_id']);
        $dormitory_id = $this->request->get('dormitory_id', 0);
        $date_type = $this->request->get('date_type', 1);
        return $this->buildSuccess([
            'list' => HomeStatisticsModel::userActiveCount($school_id,$dormitory_id,$date_type)
        ]);
    }

    /**
     * @func unlockCount
     * @param school_id 学校id
     * @method GET
     * @desc 宿舍楼今日开锁次数统计
     * @return Response
     * @Time: 2022/1/11 18:10
     */
    public function unlockCount(): Response
    {
        $school_id = $this->request->get('school_id', $this->userInfo['school_id']);
        return $this->buildSuccess([
            'list' => HomeStatisticsModel::dorUnlockCount($school_id)
        ]);
    }

    /**
     * @brief 接口名称
     * @func rkeUnlockCount
     * @param school_id 学校id sex 性别
     * @method GET
     * @desc 获取今日门禁开锁次数统计
     * @return Response
     * @Time: 2022/1/11 18:11
     */
    public function rkeUnlockCount(): Response
    {
        $school_id = $this->request->get('school_id', $this->userInfo['school_id']);
        $sex = $this->request->get('sex') == 'all' ? null : $this->request->get('sex');
        return $this->buildSuccess([
            'list' => HomeStatisticsModel::rkeUnlockCount($school_id, $sex)
        ]);
    }
}